USE [GHBank]
IF EXISTS (SELECT 1
          FROM SYSOBJECTS
          WHERE  id = OBJECT_ID('UFN_GetHirachyPrefix2')
          AND TYPE IN ('F','FN'))
DROP FUNCTION UFN_GetHirachyPrefix2
GO
/****** Object:  UserDefinedFunction [dbo].[UFN_GetHirachyPrefix2]    Script Date: 11/29/2010 14:59:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		AKE
-- Create date: 1:34 PM 8/5/2010
-- =============================================
CREATE FUNCTION [dbo].[UFN_GetHirachyPrefix2]
(
	@hirachy_level int
)
RETURNS varchar(max)
AS
BEGIN
	
	
	
	declare @prefix varchar(max)
	set		@prefix = '';

	--==========================================================
	--Generate prefix by level count
	--==========================================================
	while @hirachy_level > 0 begin
		set @prefix = '-- ' + @prefix;
		set @hirachy_level = @hirachy_level - 1;
	end
	
	-- Return the result of the function
	RETURN @prefix;

END
